<?php

namespace mpend\modules\activity\models;

use common\models\shop\ShopActivityProduct;

/**
 * ActivityProductSearch is the search model class for table "{{%shop_activity_product}}".
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class ActivityProductSearch extends \mpend\models\searchs\ProductSearch {

    public $activity_id;

    /**
     * {@inheritdoc}
     */
    public function rules() {
        $rules = parent::rules();
        $rules[] = [['actid'], 'safe'];
        return $rules;
    }

    public function getSpecialProduct() {
        return $this->hasOne(ShopActivityProduct::className(), ['product_id' => 'id']);
    }

    public function buildQuery() {
        $query = static::find()->alias('t')->active(static::STATUS_ACTIVE);
        $query->innerJoinWith('stats s', true);
        $query->innerJoinWith('specialProduct sp');
        $query->andWhere(['sp.activity_id' => $this->activity_id]);
        return $query;
    }

}
